import {
  Entity,
  Column,
  CreateDateColumn,
  OneToOne,
  JoinColumn,
  JoinTable,
  ManyToMany,
  PrimaryColumn
} from "typeorm";

import { BblDeskType } from "./desk-type.entity";
import { BblDeskBrand } from "./desk-brand.entity";
import { BblAttach } from "./attach.entity";

/**
 * 球桌表
 */
@Entity("BBL_DESK")
export class BblDesk {
  @PrimaryColumn({
    name: "DESK_ID",
    type: "varchar",
    length: 50,
    comment: "球桌ID"
  })
  deskId: string;

  @Column({
    name: "DESK_NAME",
    type: "varchar",
    length: 255,
    nullable: false,
    comment: "球桌名称"
  })
  deskName: string;

  /**
   * 球桌缩略图
   */
  @OneToOne((type) => BblAttach, { createForeignKeyConstraints: false })
  @JoinColumn({
    name: "DESK_THUMB_ID"
  })
  deskThumb: BblAttach;

  @ManyToMany((type) => BblAttach, { createForeignKeyConstraints: false })
  @JoinTable({
    name: "BBL_DESK_PARAM_IMG",
    joinColumn: {
      name: "DESK_ID",
      referencedColumnName: "deskId"
    },
    inverseJoinColumn: {
      name: "ATTACH_ID",
      referencedColumnName: "attId"
    }
  })
  deskParamImgs: BblAttach[];

  @OneToOne((type) => BblDeskBrand, { createForeignKeyConstraints: false })
  @JoinColumn({
    name: "DESK_BRAND_ID",
    referencedColumnName: "deskBrandId"
  })
  deskBrand: BblDeskBrand;

  @OneToOne((type) => BblDeskType, { createForeignKeyConstraints: false })
  @JoinColumn({
    name: "DESK_TYPE_ID",
    referencedColumnName: "deskTypeId"
  })
  deskType: BblDeskType;

  @Column({
    type: "float",
    name: "DESK_PRICE",
    nullable: false,
    comment: "球桌价格"
  })
  deskPrice: number;

  @Column({
    name: "DESK_REMARK",
    type: "varchar",
    length: 2000,
    nullable: true,
    comment: "备注"
  })
  deskRemark: string;

  @Column({
    name: "IS_DELETED",
    type: "int",
    nullable: true,
    comment: "是否删除，0：未删除，1：已删除"
  })
  deskIsDeleted: number;

  @Column({
    name: "DESK_INDEX",
    type: "int",
    nullable: true,
    comment: "排序"
  })
  deskIndex: number;

  @CreateDateColumn({
    name: "CREATED_AT",
    type: "timestamp",
    nullable: true,
    comment: "最后登录时间"
  })
  createdAt: Date;
}
